package leetcode_2101_2200;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_2147 {
    public static void main(String[] args) {
//        System.out.println(numberOfWays("SSPPSPS"));
//        System.out.println(numberOfWays("PPSPSP"));
//        System.out.println(numberOfWays("SSS"));
        System.out.println(numberOfWays("SSPSSPSS"));
    }
    private static int numberOfWays(String corridor) {
        char[] s = corridor.toCharArray();
        int n = s.length;
        List<int[]> list = new ArrayList<>();
        int p = -1;
        for (int i = 0; i < n; i++) {
            char c = s[i];
            if (c == 'S'){
                if (p == -1){
                    p = i;
                }else {
                    list.add(new int[]{p, i});
                    p = -1;
                }
            }
        }
        if (p != -1 || list.size() == 0)
            return 0;
        long ans = 1, mod = (long) (1e9 + 7);
        int pre = list.get(0)[1];
        int m = list.size();
        for (int i = 1; i < m; i++) {
            int[] ints = list.get(i);
            int l = ints[0];
            int c = 1;
            if (l != 0){
                c = l - pre;
            }
            c = Math.max(1, c);
            ans *= c;
            ans %= mod;
            pre = ints[1];
        }
        return (int) ans;
    }
}